Skip to content

fix: find groups declared with upper case letters - #705

Open
lbarrosby wants to merge 2 commits into
creativeprojects:masterfrom
lbarrosby:fix-group-name-case
Open

lbarrosby wants to merge 2 commits into
creativeprojects:masterfrom
lbarrosby:fix-group-name-case

Conversation

@lbarrosby

Copy link
Copy Markdown
Contributor

Fixes #646

Viper stores every configuration key in lower case. Profiles are looked up through viper (IsSet/Sub), which ignores case, so -n Dom finds Dom. Groups are loaded once into cached.groups, keyed by the lower-case names viper returns, and HasProfileGroup/GetProfileGroup index that map with the name exactly as typed. A group declared as W1 is therefore only reachable as -n w1, which is the inconsistency the issue describes.

With the config from the issue (v2, group W1: profiles: [Dom, Ha]) and a stub restic:

# master
$ resticprofile -c g.yaml -n W1 --dry-run backup
profile or group not found: "W1"
$ resticprofile -c g.yaml -n W1 show
profile or group 'W1': not found

# this branch
$ resticprofile -c g.yaml -n W1 --dry-run backup
profile 'Dom': starting 'backup'
profile 'Dom': finished 'backup'
profile 'Ha': starting 'backup'
profile 'Ha': finished 'backup'

Change: a small lookupGroup helper tries the name as given, then in lower case. Both HasProfileGroup and GetProfileGroup use it, so the run, show and the schedule commands behave the same. The profile names inside the group are not touched: they already resolve in any case, as the issue notes.

Test: TestGetProfileGroupMixedCase (v1 TOML and v2 YAML) checks W1 and w1 both find the group and W2 does not. It fails on master for W1.

$ go test -short ./config/
$ TEST_HELPERS=$PWD/build/ go test -short . ./monitor/...
$ go vet ./config/ && golangci-lint run ./config/

I used an AI assistant (Claude) to help with this change; I reviewed it and ran the checks above myself.

Configuration keys are stored in lower case, so a group declared as W1
was only found with "-n w1", while "-n Dom" finds profile Dom. Fall
back to the lower case name when looking up a group.

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.43%. Comparing base (daeff82) to head (80fb298).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #705      +/-   ##
==========================================
+ Coverage   85.42%   85.43%   +0.01%     
==========================================
  Files         161      161              
  Lines       10399    10403       +4     
==========================================
+ Hits         8883     8887       +4     
  Misses       1516     1516              
Flag Coverage Δ
unittests 83.35% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@creativeprojects creativeprojects left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR 👍🏻

@creativeprojects creativeprojects left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I just re-read the bug report 🤔

The issue wasn't that he couldn't load the group as w1, but is that when the profiles were written lowercase it couldn't load them. I understand this issue to be with this config:

version: 2
groups:
  W1:
    profiles: [ dom, ha ]

profiles:
  Dom:
    inherit: default
  Ha:
    inherit: default

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Profile group lookup now checks the supplied name and, if needed, its lowercase form. Tests verify both forms against TOML and version 2 YAML configurations.

Changes

Profile group lookup

Layer / File(s) Summary
Group lookup and validation
config/config.go, config/config_group_test.go
HasProfileGroup and GetProfileGroup use a helper that checks the exact group name and then its lowercase form. Tests verify lookup for W1 and w1, and confirm that W2 is not recognised.

Estimated code review effort: 2 (Simple) | ~7 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: jkellerer

Merge Risk: Minimal · up to 80fb2

Group names written with uppercase letters can now be found as typed or in lowercase. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: groups declared with upper-case letters are now found when the name is typed in that case. It matches the objective of making groups reachable using the name as typed…
Description check Passed The description explains the cause (Viper lower-casing keys, while group lookups use the typed name), the change (a lookupGroup helper that tries the exact name, then lower case), before-and-after rep…
Linked Issues check Passed Directly linked issue #646 asks that group names and their handling be case-consistent in version 2 configurations. The diff at the merge base changes HasProfileGroup and GetProfileGroup to use a …
Out of Scope Changes check Passed The whole-PR changes are limited to the lookup helper in config/config.go, its use in HasProfileGroup and GetProfileGroup, and the new test TestGetProfileGroupMixedCase in config/config_group_te…
Full details: Title check

Explanation

The title states the main change: groups declared with upper-case letters are now found when the name is typed in that case. It matches the objective of making groups reachable using the name as typed, and it follows the conventional fix: prefix.

Full details: Description check

Explanation

The description explains the cause (Viper lower-casing keys, while group lookups use the typed name), the change (a lookupGroup helper that tries the exact name, then lower case), before-and-after reproduction output, and the test added. It is directly related to the changeset.

Full details: Linked Issues check

Explanation

Directly linked issue #646 asks that group names and their handling be case-consistent in version 2 configurations. The diff at the merge base changes HasProfileGroup and GetProfileGroup to use a new lookupGroup helper (config/config.go). The helper tries the name as typed, then its lower-case form, against cached.groups, whose keys are lower case. A group declared as W1 is therefore found by W1 and w1. Both the run path and show use these methods, so the behaviour is consistent. The issue offers either normalising the profiles array or making case handling consistent. This PR makes group-name lookup case-insensitive. The PR states that profile names inside the group already resolve in any case, because viper lookups ignore case. I did not separately reproduce that array behaviour. TestGetProfileGroupMixedCase covers W1, w1 and the negative case W2 for v1 and v2 configurations.

Full details: Out of Scope Changes check

Explanation

The whole-PR changes are limited to the lookup helper in config/config.go, its use in HasProfileGroup and GetProfileGroup, and the new test TestGetProfileGroupMixedCase in config/config_group_test.go. The helper and the test both relate directly to the group-name case issue #646. No unrelated file or behaviour change appears in the reviewed evidence.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e9b3e841-f281-4af4-a488-696c093f1a48
Commits

Reviewing files that changed from the base of the PR and between daeff82 and 80fb298.

Files selected for processing: 2

  • config/config.go
  • config/config_group_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistency in case-sensitivity between group names and profiles array (version 2)

2 participants